/*
 *
 * Copyright 2018-2020,2022-2024 NXP.
 *
 * NXP Confidential. This software is owned or controlled by NXP and may only be
 * used strictly in accordance with the applicable license terms. By expressly
 * accepting such terms or by downloading,installing, activating and/or otherwise
 * using the software, you are agreeing that you have read,and that you agree to
 * comply with and are bound by, such license terms. If you do not agree to be
 * bound by the applicable license terms, then you may not retain, install, activate
 * or otherwise use the software.
 *
 */

#ifndef UWBAPI_TYPES_PROPRIETARY_SR040_H
#define UWBAPI_TYPES_PROPRIETARY_SR040_H

#include "UwbApi_Types.h"
#include "uci_ext_defs.h"
#include "phUwbTypes.h"

/**  UWBS response timeout*/
#define UWB_MAX_DEV_MGMT_RSP_TIMEOUT (1000 + 500)
/* DPD Timeout Range */
#if UWBIOT_TML_SPI
/**  When running natively, time depends on underlying HW, but save power */
#define UWBD_DPD_TIMEOUT_MIN 1
#else
/**  When running from PC, Relax a bit. */
#define UWBD_DPD_TIMEOUT_MIN 100
#endif

#define UWBD_DPD_TIMEOUT_MAX 5000

/**  Maximum timeout Supported by UWBS */

/* HPD Timeout Range */
/**  Minimum timeout Supported by UWBS */
#if UWBIOT_TML_SPI
/**  When running natively, time depends on underlying HW, but save power */
#define UWBD_HPD_TIMEOUT_MIN 2
#else
#define UWBD_HPD_TIMEOUT_MIN 100
#endif

/**  Maximum timeout Supported by UWBS */
#define UWBD_HPD_TIMEOUT_MAX 5000

/**  Time out value for calibration notification */
#define UWBD_TEST_MODE_NTF_TIMEOUT 2000

/**  Max value of Response Length for Radio Config get version command */
#define UWB_MAX_RADIO_CONFIG_VERSION_LEN 0x08

/** Value to be dedected for the Xtal Lenght  */
#define DEDECTED_XTAL_LENGHT_LEN 7

/** Max Value for the XTAL VALUE IS */
#define MAX_XTAL_VALUE \
    ((MAX_UCI_PACKET_SIZE - DEDECTED_XTAL_LENGHT_LEN) / 2) /* (255-2(startaddress)-2(lenght)-3(header and lenght)/2 */

/* Values for the Slow Blink Interval
 * MIN 1 sec
 * MAX 55 Mins (55*60)
 * */

/** seconds */
#define SLOW_BLINK_INTERVAL_MIN_VALUE 1
//#define SLOW_BLINK_INTERVAL_VALUE     10
#define SLOW_BLINK_INTERVAL_MAX_VALUE (55 * 60)

#define MODELID_BOARD_TYPE kChipType_SR040
#define MODELID_CHIP_TYPE  kChipType_SR040

/** \addtogroup uwb_status
 * @{ */
/**
 * @brief Status Codes for SR040.
 */
/** Battery low  error status*/
#define UWBAPI_STATUS_LOW_POWER_ERROR 0xFE

/** @} */ /* @addtogroup uwb_status */

/** Extended psdu header length offset **/
#define EXT_PSDU_LEN_OFFSET 0x04

/** \weakgroup uwb_apis_sr040
 *
 * SR040 APIs
 *
 * @{
 */

/**
 * @brief  Structure lists out the UWB Device Info Parameters.
 */
typedef struct phUwbDevInfo
{
    /** UCI generic version */
    uint16_t uciGenericVersion;
    /** Mac Major version */
    uint8_t macMajorVersion;
    /** Mac Minor version */
    uint8_t macMinorMaintenanceVersion;
    /** Phy Major version */
    uint8_t phyMajorVersion;
    /** Phy Minor version */
    uint8_t phyMinorMaintenanceVersion;
    /** UCI test version */
    uint16_t uciTestVersion;
    /** Device Name */
    uint8_t devName[UCI_EXT_PARAM_ID_DEVICE_NAME_LEN];
    /** Fw Major Version */
    uint8_t fwMajor;
    /** Fw Minor Version */
    uint8_t fwMinor;
    /** Fw Patch Version */
    uint8_t fwPatchVersion;
    /** MW Major Version */
    uint8_t mwMajor;
    /** MW Minor Version */
    uint8_t mwMinor;
    /** Device Minor Version */
    uint8_t devMinor;
    /** Device Major Version */
    uint8_t devMajor;
    /** Serial No */
    uint8_t serialNo[UCI_EXT_PARAM_ID_SERIAL_NUMBER_LEN];
    /** DSP Fw Major Version */
    uint8_t dspMajor;
    /** DSP Fw Minor Version */
    uint8_t dspMinor;
    /** DSP Fw Patch Version */
    uint8_t dspPatchVersion;
    /** Fw Major Version */
    uint8_t bbMajor;
    /** Fw Minor Version */
    uint8_t bbMinor;
    /** Fw Patch Version */
    uint8_t bbPatchVersion;
    /** Fw Patch Version */
    uint8_t cccVersion[UCI_EXT_PARAM_ID_CCC_VERSION_LEN];
} phUwbDevInfo_t;

typedef enum testNtfState
{
    TEST_STOP_NTF_NOT_RECEIVED = 0x00,
    TEST_STOP_NTF_RECEIVED     = 0x01,
} etestNtfState;

/**
 * @brief  UWB SWUP TYPE.
 */
typedef enum UwbSwupMode
{
    /** SWUP FW */
    UwbSwupMode_FW,
    /** SWUP DSP */
    UwbSwupMode_DSP,
    /*swup unkownon mode*/
    UwbSwupMode_Unkown = 0XFF
} eUwbSwupMode;

/**
 *  @brief SetApp Configuration parameters supported in UWB API layer.
 */
typedef enum appConfig
{
    /** Ranging Method
     *
     *  - 0:TDoA
     *  - 1:SS-TWR with Deferred Mode
     *  - 2:DS-TWR with Deferred Mode
     *  - 3:SS-TWR with Non-Deferred Mode
     *  - 4:DS-TWR with Non-Deferred Mode
     *  - 6:TDoA with Advertisement */
    RANGING_ROUND_USAGE = 0x01,
    /** STS Config
     *  - 0:Static STS
     *  - 1:Dynamic STS
     *  - 2:Dynamic STS for controlee individual key
     *  - 3:Provisioned STS
     *  - 4:Provisioned STS for Responder specific Sub-session Key
     *  - 5 to 0xFF : RFU
     */
    STS_CONFIG = 0x02,
    /**  5,6,8,9 */
    CHANNEL_NUMBER = 0x04,
    /** Number of Controlees */
    NO_OF_CONTROLEES = 0x05,
    /** Destination MAC Addr */
    DST_MAC_ADDRESS = 0x07,
    /**  Slot duration in RSTU(Ranging/Radar Standard Time Unit) */
    SLOT_DURATION = 0x08,
    /**  Ranging Duration in ms */
    RANGING_DURATION = 0x09,
    /**  STS index init value */
    STS_INDEX = 0x0A,
    /**  0:CRC16, 1:CRC32 */
    MAC_FCS_TYPE = 0x0B,
    /**
     * - 1:Enable,
     * - 0:Disable
     *
     * - b0 - Measurement Report Phase,
     * - b1 - Ranging Control Phase
     * - b2 : b7 - RFU
     * (default = 0x03) */
    RANGING_ROUND_CONTROL = 0x0C,
    /** 0: AOA Disable, 1: AOA Enable */
    AOA_RESULT_REQ = 0x0D,
    /**  0:Disable, 1:Enable, 2:Enable in proximity range */
    SESSION_INFO_NTF = 0x0E,
    /**  Proximity near in cm */
    NEAR_PROXIMITY_CONFIG = 0x0F,
    /**  Proximity far in cm */
    FAR_PROXIMITY_CONFIG = 0x10,
    /**
     *  0x00 = Responder
     *  0x01 = Initiator
     *  0x02 = UT-Synchronization Anchor
     *  0x03 = UT-Anchor
     *  0x04 = UT-Tag
     *  Values 0x05 to 0xFF = RFU
     */
    DEVICE_ROLE = 0x11,
    /**  0:No STS, 1:STS follows SFD, 2:STS follows PSDU, 3:STS follows SFD */
    RFRAME_CONFIG = 0x12,
    /**  [9-12]:BPRF, [25-32]:HPRF */
    PREAMBLE_CODE_INDEX = 0x14,
    /**  [0,2]:BPRF, [1,3]:HPRF */
    SFD_ID = 0x15,
    /** PSDU DATA RATE
     * 0x00 = 6.81 Mbps (default)
     * 0x01 = 7.80 Mbps
     * 0x02 = 27.2 Mbps
     * 0x03 = 31.2 Mbps
     * 0x04 = 850 Kbps
     */
    PSDU_DATA_RATE = 0x16,
    /**  0:32 symbols, 1:64 symbols */
    PREAMBLE_DURATION = 0x17,
    /**  0x00 – Bypass Mode (Default), 0x01 – Connection-Less data transfer */
    LINK_LAYER_MODE = 0x18,
    /**  0x00 – No repetition (Default), 0xFF – Repeat infinite number of times */
    DATA_REPETITION_COUNT = 0x19,
    /**  1:Block based & 0:[2-255]:RFU */
    RANGING_TIME_STRUCT = 0x1A,
    /**  Slot per Ranging Round, Not applicable for Contention Based Ranging */
    SLOTS_PER_RR = 0x1B,
    /**  0:Disable, 1:Enable */
    TX_ADAPTIVE_PAYLOAD_POWER = 0x1C,
    /**  0: BPRF, 1:HPRF */
    PRF_MODE = 0x1F,
    /**  1: Enable, 0:Disable [Default] */
    KEY_ROTATION = 0x23,
    /**  Session Priority 1-100, default : 50 */
    SESSION_PRIORITY = 0x25,
    /**  MAC address mode Default 0 [SHORT] */
    MAC_ADDRESS_MODE = 0x26,
    /** Vendor ID */
    VENDOR_ID = 0x27,
    /** Static STS IV */
    STATIC_STS_IV = 0x28,
    /** Number of STS segments in the frame.
     * 0x00:No STS Segments (if RFRAME_CONFIG is 0).
     *
     * If RFRAME_CONFIG Config is set to 1 or 3 then
     *
     * - 0x01:1 STS Segment(default)
     * - 0x02:2 STS Segments */
    NUMBER_OF_STS_SEGMENTS = 0x29,

    /**  Maximum Ranging Round Retry */
    MAX_RR_RETRY = 0x2A,
    /**  Ranging round hopping, 1=Enable, 0=Disable [Default] */
    HOPPING_MODE = 0x2C,
    /** Config to enable result report, 0: Disable, This is applicable only RANGING_ROUND_CONTROL enabled */
    RESULT_REPORT_CONFIG = 0x2E,
    /** PHR coding rate:
     * 0x00 = 850 kbps (default)
     * 0x01 = 6.81 Mbps
     */
    BPRF_PHR_DATA_RATE = 0x31,
    /**Maximum Number of ranging blocks to executed in a session  Default : 0*/
    MAX_NUMBER_OF_MEASUREMENTS = 0x32,
    /** This parameter specifies the average transmission interval of Blink UTMs from
     *  UT-Tags and/or Synchronization UTMs from UT-Synchronization Anchors, as defined
     *  by the UL-TDoA TX Interval MAC configuration parameter.
     *
     *  By default, UL_TDOA_TX_INTERVAL = 2000ms.
     */
    UL_TDOA_TX_INTERVAL = 0x33,
    /** Length of the randomization window within which Blink and Synchronization UTMs may be transmitted. */
    UL_TDOA_RANDOM_WINDOW = 0x34,
    /** STS length 0: 32 symbols , 1: 64 symbols(Default), 2: 128 symbols */
    STS_LENGTH = 0x35,
    /** This value shall be used to specify the length and presence of the UL-TDoA Device ID in UTMs. */
    UL_TDOA_DEVICE_ID = 0x38,
    /** Presence and length of TX timestamps in UTMs.
     * 0x00: TX timestamp shall not be included (default).
     * 0x01: 40-bit TX timestamp shall be included.
     * 0x02: 64-bit TX timestamp shall be included.
     * Values 0x03 to 0xFF = RFU
     *
     * By default, TX timestamps shall not be included.
     */
    UL_TDOA_TX_TIMESTAMP = 0x39,
    /**Session Key provided for Provisioned STS mode (STS_CONFIG equal to 0x03 or 0x04)
     * If the Session Key is not provided by the Host in Provisioned STS mode, the UWBS shall fetch the Session Key from
     * the Secure Component. This parameter is valid only in Provisioned STS mode and shall be ignored otherwise.*/
    SESSION_KEY = 0x45,
    /**Sub-session Key provided for Provisioned STS for Responder specific Key mode (STS_CONFIG equal to 0x04).
     * If the Sub-session Key is provided by the Host, the Host shall also provide the SESSION_KEY.
     * If the Sub-session Key is not provided by the Host for Provisioned STS for Responder specific Key mode, the UWBS
     * shall fetch the Sub-session Key from the Secure Component. This parameter is valid only in Provisioned STS for
     * Responder specific Key mode and shall be ignored otherwise.*/
    SUB_SESSION_KEY = 0x46,
    END_OF_SUPPORTED_APP_CONFIGS,
    /** This parameter can be used to configure the required number of successful responses(T) from Responders to
       conclude a successful ranging round. Default : NUMBER_OF_CONTROLEES*/
    ADAPTIVE_HOPPING_THRESHOLD = 0xB0,
    /** b0: MAC header present, b1:MAC footer present */
    MAC_CFG = 0xB1,
    /** Antenna configuration for Antenna selection,
     * 0: Default. ANT_DEFAULT selected. No GPIO Toggle required. Legacy antenna selection.
     * 1: ANT-TOP selected for Tx/Rx . GPIO set to output, value= 0.
     * 2: ANT-BOTTOM selected for Tx/Rx. GPIO set to output, value =1.
     */
    ANTENNA_CONFIG = 0xB2,
    /** Parameter to select MAC frame format for UL-TDOA Tag device
     *  0x00: FIRA(default)
     *  0x01: Vendor-specific MAC format
     *  Note: This parameter is only applicable when RANGING_ROUND_USAGE = 0x00
     *  (One Way Ranging UL-TDoA) and DEVICE_ROLE = 0x04 (UT-Tag)
     */
    ULTDOA_MAC_FRAME_FORMAT = 0xB3,
    /** Parameter to configure the time offset of first ranging block (in ms) 0..200 ms
     *  default: 0 ms (No offset)
     */
    RANGING_START_OFFSET = 0xB4,
    /** Receiver window start margin */
    RX_START_MARGIN = 0xE3,
    /** Receiver window length */
    RX_TIMEOUT = 0xE4,

    /**
     * PHSCA_UCIMSG_SESSION_NBIC_CONF_ID - 0xF2u
     *
     * NBIC disabled - 0u,
     * NBIC enabled - 1u,
     * NBIC enabled FS mode enabled - 2,
     */
    SR040_NBIC_CONF = 0xE6,
    SALTED_HASH     = 0xEC,
    D_URSK          = 0xED,
    /** TX Power ID
     * - 0: max power (14db)
     * - 104: least power(-12db)
     *
     * Range 0 to 104: 0.25db per step */
    TX_POWER_ID = 0xF2,
    /* Internal  parameter */
    DEBUG_LOG_LEVEL = 0xF3,
    /**  Phy logging for Test Receive Mode, 1=Enable, 0=Disable [Default] */
    RX_PHY_LOGGING_ENABLE = 0xF4,
    /**  Phy logging for Test Transmit Mode, 1=Enable, 0=Disable [Default] */
    TX_PHY_LOGGING_ENABLE = 0xF5,
    /* Internal Parameter */
    LOG_PARAMS_CONF = 0xF6,
    /**  Sts Index Restart */
    STS_INDEX_RESTART = 0xF9,
    /**  RX radio configuration slot index in flash
     * - Low byte indicates slot index for SP0 type
     * - High byte indicates slot index for SP3 type
     * Minimum slot index: 0x10, Maximum slot index: 0x1F
     * Default: 0x0100 [SP3(High Byte): index 0x01, SP0(Low Byte): index 0x00]
     */
    RX_RADIO_CFG_IDXS = 0xFB,
    /**  TX radio configuration slot index in flash
     * - Low byte indicates slot index for SP0 type
     * - High byte indicates slot index for SP3 type
     * Minimum slot index: 0x10, Maximum slot index: 0x1F
     * Default: 0x1110 [SP3(High Byte): index 0x11, SP0(Low Byte): index 0x10]
     */
    TX_RADIO_CFG_IDXS   = 0xFC,
    SR040_INTERNAL_0xFD = 0xFD,
    END_OF_SUPPORTED_EXT_CONFIGS,
} eAppConfig; /* Update ext_app_config_mapping when modifying this */

/**
 *   Device Configuration parameters supported in UWB API layer.
 */
typedef enum deviceConfig
{
    /** 0:DISABLE, 1:ENABLE */
    LOW_POWER_MODE = 0x01,
    /** DPD entry timeout in ms (default = 300ms)*/
    DPD_ENTRY_TIMEOUT = 0xE9,
    /** DPD entry timeout in ms (default = 300ms)*/
    HPD_ENTRY_TIMEOUT,
    /* MHR_IN_CCM Core Config
     * Disable : 0x00
     * Enable  : 0x01[default] */
    MHR_IN_CCM = 0xF9,
    /* DDFS TONE CONFIG ENABLE Core Config
     * Disable : 0x00 [default]
     * Enable  : 0x01 */
    DDFS_TONE_CONFIG_ENABLE = 0xFA,
    /** 0x00 = FIRA generic Response/Notification (Default)
    0x01 = Vendor extended Response/Notification */
    NXP_EXTENDED_NTF_CONFIG = 0xFB,
    END_OF_SUPPORTED_DEVICE_CONFIGS,
} eDeviceConfig;

/**
 *  @brief Set/Get App Configuration parameters type supported in UWB API layer.
 */
typedef enum UWB_AppParams_type
{
    /** We don't know the type */
    kUWB_APPPARAMS_Type_Unknown = 0,
    /** It's a 32 bit value */
    kUWB_APPPARAMS_Type_u32 = 4,
    /** It's an array of 8 bit values*/
    kUWB_APPPARAMS_Type_au8 = 5,
} UWB_AppParams_type_t;

/**
 *  @brief Set/Get App Configuration parameters value type supported in UWB API layer.
 */
typedef struct UWB_AppParams_value_au8
{
    uint8_t *param_value;
    uint16_t param_len; // Just to  handle parameter of any length
} UWB_AppParams_value_au8_t;

/**
 *  @brief Set/Get App Configuration parameters value structure supported in UWB API layer.
 */
typedef union UWB_AppParams_value {
    uint32_t vu32; // All values u8, u16 and u32 are processed here
    UWB_AppParams_value_au8_t au8;
} UWB_AppParams_value_t;

/**
 *  @brief Set/Get App Configuration parameters list supported in UWB API layer.
 */
typedef struct UWB_AppParams_List
{
    /** Input: search this tag */
    eAppConfig param_id;
    /** Filled Implicitly: Expected type. */
    UWB_AppParams_type_t param_type;
    /** Input: Parameter Value */
    UWB_AppParams_value_t param_value;
} UWB_AppParams_List_t;

/* Deprecated. Following Set app params specific defines are changed,
 * use above defines, defined here for backward compatibility */

typedef UWB_AppParams_type_t SetAppParams_type_t;

#define kAPPPARAMS_Type_Unknown kUWB_APPPARAMS_Type_Unknown
#define kAPPPARAMS_Type_u32     kUWB_APPPARAMS_Type_u32
#define kAPPPARAMS_Type_au8     kUWB_APPPARAMS_Type_au8

typedef UWB_AppParams_value_au8_t SetAppParams_value_au8_t;
typedef UWB_AppParams_value_t SetAppParams_value_t;
typedef UWB_AppParams_List_t SetAppParams_List_t;

/* End of deprecated defines */

/**
 *  @brief Macro to set SetApp Configuration parameters value supported in UWB API layer.
 */
#define UWB_SET_APP_PARAM_VALUE(PARAM, VALUE)                                                      \
    {                                                                                              \
        .param_id = (PARAM), .param_type = (kUWB_APPPARAMS_Type_u32), .param_value.vu32 = (VALUE), \
    }

/**
 *  @brief Macro to set GetApp Configuration parameters value supported in UWB API layer.
 */
#define UWB_SET_GETAPP_PARAM(PARAM)                                   \
    {                                                                 \
        .param_id = (PARAM), .param_type = (kUWB_APPPARAMS_Type_u32), \
    }

/**
 *  @brief Macro to set SetApp/GetApp Configuration parameters array value supported in UWB API layer.
 */
#define UWB_SET_APP_PARAM_ARRAY(PARAM, ARRAY, LENGTH)                                                        \
    {                                                                                                        \
        .param_id = (PARAM), .param_type = (kUWB_APPPARAMS_Type_au8), .param_value.au8.param_len = (LENGTH), \
        .param_value.au8.param_value = (uint8_t *)(ARRAY)                                                    \
    }

/**
 *  @brief Calibrations Configuration parameters supported in UWB API layer.
 */
typedef enum calibParam
{
    /**  A difference between received and expected TX power */
    TX_POWER_DIFF = 0x0,
    /** A difference (in Hz) between received and expected UWB frequency */
    FREQ_DIFF,
    /**  Antenna delay in 15.65ps resolution */
    ANTENNA_DELAY,
    /**  Current Limiter Value, 0:minimum 20:maximum, 20:default*/
    CURRENT_LIMIT_VALUE,
    /** Groupdelays in trim page are calculated with SP3 frames flashed in radio indexes.
     *  Length - 6 Octet
     *  0: Recalculate (144 Octets ForRead trim value)
     *  Groupdelay index according to radio configuration index Groupdelay index
     *  second byte is a NBIC type (0: NBIC disabled, 1: NBIC enabled, 2: NBIC enabled with Low frequency config
     *  following 4 bytes represent an group delay in 15.65ps resolution
     *  0x0: 0 ps (no delay); 0xFFFFFFFF: 67 216 238 166,75 ps (max)
     *  By default group delay is calculated at the very first startup.*/
    GROUP_DELAY = 0x04,
    /**  Temp compens flag Value */
    TEMP_COMPENS_FLAG = 0x05,
    /**  Tx Adaptive power calc Value */
    TX_ADAPTIVE_POWER_CALC = 0x06,
    /** DDFS Tone Values */
    DDFS_TONE_VALUES = 0x07,
    /** DPD Timer Penalty in us */
    DPD_TIMER_PENALTY_US,
    /**  Enable/Disable sensor-based wakeup.
     *  1 : Enable
     *  2 : Disable(Default)
     *  Any other value is Invalid.*/
    WAKEUP_SENSOR_ENABLE,
    /** Blink interval when no movement is detected (in seconds)
        Min: 1 second.
        Max: 56 minutes.*/
    SLOW_BLINK_INTERVAL,
    /** Source of Thermistor, internal or external.
     *  0 : External Thermister (Default)
     *  1 : Internal.
     *  Only applicable when TEMP_COMPENS_FLAG is enabled */
    TEMPERATURE_SOURCE = 0x20,
    /** Value of "RP" (resistor) in Ohms present in externaltemperature sensor measurement unit
     *  Only applicable when TEMP_COMPENS_FLAG is enabled */
    THERMISTOR_RP = 0x21,
    /** LUT_XTAL
     * First 2 bytes, start address
     * Second 2 bytes, Length
     * N Even Octets Value to be written
     */
    LUT_XTAL = 0x22,
    /** LUT_TEMPRATURE
     * First 2 bytes, start address
     * Second 2 bytes, Length
     * N Even Octets Value to be written
     */
    LUT_THERMISTER = 0x23,
    /**Enable/Disable usage of customer specific LUTs
     *  1 : Enable
     *  2 : Disable(Default)
     *  Any other value is Invalid.*/
    CUSTOM_LUTS_ENBL = 0X24,
    /**Offset for custom temperature LUT (Thermistor Resistance value in Ohms corresponding to 1st TEMP LUT entry).
     * Default value 600 */
    LUT_TEMP_RT_OFFSET = 0x25,
    /**slope for custom temperature LUT (Thermistor Resistance increment in Ohms between 2 successive TEMP LUT entries).
     * Default value 100*/
    LUT_TEMP_RT_SLOPE = 0x26,
    /**Read only parameter
     * This configuration returns calculated temperature after applying applicable lookup tables.*/
    TRIMVALUES_GET_TEMPERATURE_X10 = 0x27,
    /**Trim Power control of preamble 10.
     * Default value 2*/
    TRIM_POWER_CTRL_PREAMBLE_10 = 0x30,
    /**Trim Power control of preamble 27.
     * Default value 2*/
    TRIM_POWER_CTRL_PREAMBLE_27 = 0x31,
    /**Enable/Disable usage of trim preamble 10 and 27 coefficents.
     *  1 : Enable(Default)
     *  2 : Disable
     *  Any other value is Invalid.*/
    TRIM_PREAMBLE_10_27_PAYLOAD_PS_COEFFS_OVERRIDE,
    /*Module maker id*/
    MODULE_MAKER_ID,
    /**  A difference between received and expected TX power for Bottom Antenna*/
    TX_POWER_DIFF_ANT_BOTTOM = 0x34,
    /**  Antenna delay in 15.65ps resolution for Bottom Antenna*/
    ANTENNA_DELAY_ANT_BOTTOM,
    /**  Tx Adaptive power calc Value for Bottom Antenna*/
    TX_ADAPTIVE_POWER_CALC_ANT_BOTTOM,
    /** Bit field to determine what is locked what change is no longer allowed.
     *   0- locks FREQ_DIFF.
     *   1 - locks ANTENNA_DELAY
     *   2 - locks GROUP_DELAY
     *   3 - locks TEMP_COMPENS_FLAG
     *   4 - locks TRIMVALUES_DDFS_TONE_VALUES
     *   5 - locks all parameters related to XTAL.I.e TRIMVALUES_
     *       TEMPERATURE_SOURCE, TRIMVALUES_THERMISTOR_RP,
     *       TRIMVALUES_LUT_XTAL,TRIMVALUES_LUT_TEMPERATURE,
     *       TRIMVALUES_CUSTOM_LUTS_ENBL
     *   6-31 : RFU
     *   0xFFFFFFFF - Lock Everything
     */
    TRIM_LOCK = 0xFF
} eCalibParam;

/**
 * Safeguarding update of PARTIAL XTAL Lookup Tables
 */
typedef enum GetLutCrc
{
    /*CRC VALUE FOR PPM*/
    kSR040_XTAL_LUT_CRC = 0x00,
    /*CRC VALUE FOR TEMP*/
    kSR040_Thermister_LUT_CRC = 0x01
} eGetLutCrc;

/**
 * @brief  Structure lists out the calibration command response/notification.
 */
typedef struct phCalibRespStatus
{
    /** Status */
    uint8_t status;
    /** One byte RFU in case of Do_calib command. Calibration state in
     * Get_calib command. */
    uint8_t rfu;
    /** Calibration value out */
    uint8_t calibValueOut[MAX_UCI_PACKET_SIZE];
    /** Calibration value length */
    uint16_t length;
} phCalibRespStatus_t;

/**
 *  @brief Session NVM Manage parameters supported in UWB API layer.
 */
typedef enum sessionNvmManage
{
    /* Session ID to Persist */
    SESSION_NVM_MANAGE_PERSIST = 0x00,
#if 0
    /* Session ID to Remove */
    SESSION_NVM_MANAGE_DELETE = 0x01,  /* Not available */
#endif
    /* Delete All persisted sessions */
    SESSION_NVM_MANAGE_DELETE_ALL = 0x02,
} esessionNvmManage;

/**
 *  @brief Status code for Calibration
 */
typedef enum calibStatus
{
    /**  Requested/Stored in the NVM trim data has been successfully applied */
    APPLIED = 0x00,
    /**  Data in NVM has been corrupted and it is replaced with the default trim values */
    CORRUPTED,
    /**  Operation failed to complete, previous trim configuration is still applied */
    FAILURE
} eCalibStatus;

/**
 *  @brief Radio Config Download Seqeunce
 */
typedef enum downloadSequence
{
    /** Radio Config Init Configuration Sequence */
    kSR040_RadioCrc_InitDownload = 0x00,
    /** Radio Config Download data Sequence */
    kSR040_RadioCrc_DownloadChunk,
    /** Radio Config Program flash Sequence */
    kSR040_RadioCrc_Finish,
    /** Radio Config Get CRC Sequence */
    kSR040_RadioCrc_GetCRC,
    /** RFU */
    kSR040_RadioCrc_RFU,
    /** Radio Config Get CRC for all radio settings */
    kSR040_RadioCrc_GetAllCRC,
} edownloadSequence;

/**
 * @brief  Enumeration lists out the Application Config ID value.
 */
typedef enum configType
{
    EXTENDED_APP_CONFIG_ID    = 0x0A,
    EXTENDED_DEVICE_CONFIG_ID = 0x0E
} eConfigType;

// #define INIT_CONFIG   kSR040_RadioCrc_InitDownload
// #define DOWNLOAD_DATA kSR040_RadioCrc_DownloadChunk
// #define PROGRAM_FLASH kSR040_RadioCrc_Finish
// #define GET_CRC       kSR040_RadioCrc_GetCRC

/**
 * @brief UWBD Type for Calibration Status Notification.
 */
typedef struct
{
    /** Calibration status */
    eCalibStatus status;
} phCalibrationStatus_t;

/**
 * @brief TX DIFF Calibration Data
 */
typedef struct
{
    /** channel number, [5 - 9] */
    uint8_t channelNo;
    /** sign:
     *
     * - 0: +ve,
     * - 1: -ve */
    uint8_t signVal;
    /** An absolute value in 0.25 dB steps.
     *
     * - 0: 0 dB (no offset),
     * - 1: 0.25 dB
     * - 2: 0.5db,
     * - ..
     * - 12: 3 dB (max) */
    uint8_t absoluteVal;
} phTxPowerDiffCalibData_t;

/**
 * @brief FREQUENCY DIFF Calibration Data
 */
typedef struct
{
    /** channel number, [5 - 9] */
    uint8_t channelNo;
    /** sign:
     *
     * - 0: +ve,
     * - 1: -ve */
    uint8_t signVal;
    /** Offset:
     *
     * - 0 Hz (no offset)
     * - 0x7A120: 500000 Hz (max)
     *
     * Note: This offset will be converted to PPM in 0.1 ppm
     * resolution per original frequency of each channel.
     *
     * For example, possible minimum offset frequency for Ch5
     * is 649Hz which is 0.1ppm per original frequency of Ch5 6489600Khz */
    uint32_t absoluteFreqOffset;
} phFreqDiffCalibData_t;

/**
 * @brief Antenna Delay Calibration Data
 */
typedef struct
{
    /** channel number, [5 - 9] */
    uint8_t channelNo;
    /**  antenna delay in 15.65ps
     *
     * resolution
     * - 0x0000 : 0 ps(no delay)
     * - 0xFFFF : 1 025 638.4 ps(max) */
    uint16_t antennaDelay;
} phAntennaDelayCalibData_t;

/**
 * @brief Tx Adaptive power calculation Data
 */
typedef struct
{
    /** channel number, [5 - 9] */
    uint8_t channelNo;
    /**  Power Id RMS delay in 0.25 dB steps */
    uint8_t powerIdRms;
    /** Peak Delta default 0x00 */
    uint8_t peakDelta;
} phTxAdaptivePowerCalibData_t;

/**
 * @brief DDFS Tone Configuration Data
 */
typedef struct
{
    /** channel number [5 - 9] */
    uint8_t channelNo;
    /**  RFU byte. */
    uint8_t rfu;
    /** Content of register TX_DDFS_TONE_0 */
    uint32_t txDdfsTone0RegVal;
    /** Content of register TX_DDFS_TONE_1 */
    uint32_t txDdfsTone1RegVal;
    /** Spur Duration */
    uint32_t spurDuration;
    /** Content of register GAINVAL_SET  */
    uint8_t gainvalsetRegVal;
    /** Content of register DDFSGAINBYPASS_ENBL  */
    uint8_t gainByPassEnblRegVal;
    /** Spur Periodicity */
    uint16_t spurPeriodicity;
} phDdfsToneConfigData_t;

/**
 * @brief LUT_PPM Configuration Data
 */
typedef struct
{
    /** First 2 bytes, start address  */
    uint16_t xtalStartAddress;
    /** Second 2 bytes, Length  */
    uint16_t xtalLength;
    /** N Even Octets Value to be written  */
    int16_t xtalValue[MAX_XTAL_VALUE];
} phLut_xtal;

/**
 * @brief LUT_TEMP Configuration Data
 */
typedef struct
{
    /** First 2 bytes, start address  */
    uint16_t tempStartAddress;
    /** Second 2 bytes, Length  */
    uint16_t tempLength;
    /** N Even Octets Value to be written  */
    int16_t tempValue[MAX_XTAL_VALUE];
} phLut_temp_t;

/**
 * @brief Group Delay Config Data
 */
typedef struct
{
    /**Groupdelay index*/
    uint8_t groupDelayIndex;
    /**     NBIC type
     *
     *  0 : NBIC disabled
     *  1 : NBIC enabled
     *  2 : NBIC  enabled with Low frequency config */
    uint8_t nbciType;
    /**   group delay in 15.65ps resolution*/
    uint32_t gropDelayData;
} phGroupDelayConfigData_t;

/**
 * @brief Calibration data
 */
typedef union {
    /** TX POWER DIFF Calibration Data */
    phTxPowerDiffCalibData_t txPowerDiffCalibData;
    /** TX POWER DIFF Calibration Data for Bottom Antenna*/
    phTxPowerDiffCalibData_t txPowerDiffAntBottomCalibData;
    /** FREQ DIFF Calibration Data */
    phFreqDiffCalibData_t freqDiffCalibData;
    /** Antenna Delay Calibration Data */
    phAntennaDelayCalibData_t antennaDelayaCalibData;
    /** Antenna Delay Calibration Data for Bottom Antenna*/
    phAntennaDelayCalibData_t antennaDelayAntBottomCalibData;
    /** Current Limit Value */
    uint8_t currLimitValue;
    /** Tx Adaptive power Calibration Data */
    phTxAdaptivePowerCalibData_t txAdaptivePowerCalibData;
    /** Tx Adaptive power Calibration Data for Bottom Antenna*/
    phTxAdaptivePowerCalibData_t txAdaptivePowerAntBottomCalibData;
    /** DDFS tone config data for all channels */
    phDdfsToneConfigData_t ddfsToneConfigData[4];
    /** temp CompesFlag 1:Disable 0:Enable */
    uint8_t tempCompensFlag;
    /** LUT XTAL Calibration Data */
    phLut_xtal lut_xtal;
    /** LUT TEMP Calibration Data */
    phLut_temp_t lut_temp;
    /**  Enable/Disable usage of customer specific LUT
     *  1 : Enable
     *  2 : Disable(Default)
     *  Any other value is Invalid.*/
    uint8_t customLutEnable;
    /** Source of Thermistor, internal or external.
     *  0 : External (Default)
     *  1 : Internal.
     *  Only applicable when TEMP_COMPENS_FLAG is enabled */
    uint8_t temperatureSource;
    /** Value of "RP" (resistor) in Ohms present in externaltemperature sensor measurement unit
     *  Only applicable when TEMP_COMPENS_FLAG is enabled */
    uint32_t thermistorRp;
    /** dpd timer penalty in us. Default value: 14917 */
    uint32_t dpdTimerPenalty;
    /** trim Backoff Pramble_10. Value is between 0 to 0xF */
    int8_t trimPowercontrolPreamble_10;
    /** trim Backoff Pramble_27. Value is between 0 to 0xF */
    int8_t trimPowercontrolPreamble_27;
    /**  Enable/Disable sensor-based wakeup.
     *  1 : Enable
     *  2 : Disable(Default)
     *  Any other value is Invalid.*/
    uint8_t wakeupSensorEnable;
    /** Blink interval when no movement is detected (in seconds)
        Min: 1 second.
        Max: 56 minutes.*/
    uint16_t slowBlinkInterval_s;
    /** Bit field to determine what is locked what change is no longer allowed.
     *   0- locks FREQ_DIFF.
     *   1 - locks ANTENNA_DELAY
     *   2 - locks GROUP_DELAY
     *   3 - locks TEMP_COMPENS_FLAG
     *   4 - locks TRIMVALUES_DDFS_TONE_VALUES
     *   5 - locks all parameters related to XTAL.I.e TRIMVALUES_
     *       TEMPERATURE_SOURCE, TRIMVALUES_THERMISTOR_RP,
     *       TRIMVALUES_LUT_XTAL,TRIMVALUES_LUT_TEMPERATURE,
     *       TRIMVALUES_CUSTOM_LUTS_ENBL
     *   6-31 : RFU
     *   0xFFFFFFFF - Lock Everything
     */
    uint32_t trimLock;
    /**Offset for custom temperature LUT (Thermistor Resistance value in Ohms corresponding to 1st TEMP LUT entry).
     * Default value 600 */
    uint16_t lutTempRtOffset;
    /**slope for custom temperature LUT (Thermistor Resistance increment in Ohms between 2 successive TEMP LUT entries).
     * Default value 100*/
    uint16_t lutTempRtSlope;
    /** Temperature X10. 227 = 22.7 degrees */
    int16_t tempX10;
    /** Groupdelay index according to radio configuration index */
    phGroupDelayConfigData_t groupDelay;
    /** preamble Payload Coeff Override 1:Enable(default) 0:Disable */
    uint8_t preamblePayloadCoeffOverride;
    /**Module Maker ID */
    uint16_t moduleMakerId;
} phCalibrationData; /* Union */

/**
 *  @brief Enum defined for Test Mode Start/Stop
 */
typedef enum testMode
{
    /** Start Device in TEST_RECEIVE_MODE */
    RECEIVE_MODE = 0x00,
    /** Start Device in TEST_TRANSMIT_MODE */
    TRANSMIT_MODE,
    /** Start Device in TEST_CONTINUOUS_WAVE_MODE */
    CONTINUOUS_WAVE_MODE,
    /** Start Device in TEST_LOOP_BACK_MODE */
    LOOP_BACK_MODE,
    /** Start Device in TEST_LOOP_BACK_MODE_NVM_AND_SAVE */
    LOOP_BACK_MODE_NVM_AND_SAVE = 0x05,
    /** SS-TWR Mode */
    SS_TWR_MODE,
} eTestMode;

/** Slot type in test mode Tx/Rx */
typedef enum
{
    kUWB_SR040_TxRxSlotType_SP0 = 0,
    kUWB_SR040_TxRxSlotType_SP1 = 1,
    kUWB_SR040_TxRxSlotType_SP3 = 3,
} UWB_SR040_TxRxSlotType_t;

/** External Wakeup_soure Parameters */
typedef enum
{
    kexternal_wakeup_source_enable  = 1,
    kexternal_wakeup_source_disable = 2,
} externalwakeup_soure;

/** Enable/Disable usage of customer specific LUTs */
typedef enum
{
    kcustom_lut_enable  = 1,
    kcustom_lut_disable = 2,
} custom_lut_enable;

/** Enable/Disable usage of Preamble 10 and 27 coeff override */
typedef enum
{
    kcoeffs_override_enable  = 1,
    kcoeffs_override_disable = 2,
} trim_preamble_coeffs_override;

/**
 * @brief Common Params used in Tx & Rx Test Mode
 */
typedef struct
{
    /** Start Delay in Micro Seconds, Default is 0 */
    uint16_t startDelay;
    /** Test Slot Type, 0x00 : SP0 type which has only PSDU without STS
                        0x03 : SP3 type which has only STS
                        Default: 0x00 SP0 */
    UWB_SR040_TxRxSlotType_t slotType;
    /** Specifies at which number of events the testmode will be stopped.
        0x00 means transmit/receive infinite number of events
        Default : 0x00 */
    uint32_t eventCounterMax;
} phRxTxCommonParams_t;

/**
 * @brief Structure required for #RECEIVE_MODE
 */
typedef struct
{
    /** Params common for Tx & Rx Test Mode */
    phRxTxCommonParams_t commonParams;
    /** Timeout value for Receive Mode in ms resolution 1 LSB = 1ms
                        Timeout shall be equal at least 1ms.
                        Default: 100ms */
    uint16_t timeOut;
    /** Cycle time for periodic mode. Defined from Start of RX to Start of next RX.
        1 LSB = 1us. (Min. value should be 1000us,
        otherwise we would need complex error handling based on frame
        length settings)
        Should be in range [1000us .. 10s] = [0x3E8us .. 0x989680us]
        Default: 1000us */
    uint32_t cycleTime;
    /* Enable or Disable Psdu Logging */
    uint8_t enableLogging;
} phReceiveModeParams_t;

/**
 * @brief Structure required for #TRANSMIT_MODE
 */
typedef struct
{
    /** Params common for Tx & Rx Test Mode */
    phRxTxCommonParams_t commonParams;
    /** Payload for Transmit Mode
        For SP0 this is mandatory parameter. */
    uint8_t const *psduData;
    /* Length of the PSDU */
    uint16_t psduLen;
    /** Cycle time for periodic mode. Defined from Start of TX to Start of next TX.
        1 LSB = 1us. (Min. value should be 1000us,
        otherwise we would need complex error handling based on frame
        length settings)
        Should be in range [1000us .. 10s] = [0x3E8us .. 0x989680us]
        Default: 1000us */
    uint32_t cycleTime;
    /* Enable or Disable Psdu Logging */
    uint8_t enableLogging;
} phTransmitModeParams_t;

/**
 * @brief Test Mode Params
 */
typedef union {
    /** Structure to be used when #RECEIVE_MODE is the input */
    phReceiveModeParams_t receiveModeParams;
    /** Structure to be used when #TRANSMIT_MODE is the input */
    phTransmitModeParams_t transmitModeParams;
} phTestModeParams;

/**
 * @brief UWBD Type for Test Loopback Status Notification.
 */
typedef struct
{
    /** Generic Status Code */
    uint8_t status;
    /** Calculated Group Delay */
    uint32_t groupDelay;
} phTestLoopbackData_t;

/**
 * @brief Test Initiator Range Status Notification.
 */
typedef struct
{
    /** Session ID of the currently active session */
    uint32_t sessionId;
    /** Current Block Index */
    uint16_t blockIndex;
    /** STS index of RMI */
    uint32_t stsIndex;
    /** Next Ranging Round Index */
    uint16_t rrIndex;
} phTestInitiatorRangekData_t;

/**
 * @brief Phy Log Notification.
 */
typedef struct
{
    /** Size of data */
    uint16_t size;
    /** Data received part of phy log */
    uint8_t data[MAX_HPRF_PSDU_DATA_PACKET_SIZE];
} phPhyLogNtfnData_t;

/**
 * @brief Test Mode Output Data
 */
typedef union {
    /** Structure to be used for Test Loopback Status Notification */
    phTestLoopbackData_t loopBackData;
} phTestModeOutputData;

/**
 * @brief Radio Config Get Version command response.
 */
typedef struct phRadioConfigGetVersionResp
{
    /** Major Version of the corresponding Rx/Tx Sequence */
    uint16_t major;
    /** Minor Version of the corresponding Rx/Tx Sequence */
    uint16_t minor;
    /** patch Version of the corresponding Rx/Tx Sequence */
    uint16_t patch;
} phRadioConfigGetVersionResp_t;

/**
 * @brief Device config data
 */
typedef union phDeviceConfig {
    /** low power mode */
    uint8_t lowPowerMode;
    /** DPD entry timeout */
    uint16_t dpdEntryTimeout;
    /** DPD entry timeout */
    uint16_t hpdEntryTimeout;
    /** MHR_IN_CCM */
    uint8_t mhrInCcm;
    /** DDFS tone config enable */
    uint8_t ddfsToneConfig;
    /** Tx Telec config */
    phTxPulseShapeConfig_t txPulseShapeConfig;
    /** nxp extended ntf config */
    uint8_t nxpExtendedNtfConfig;
} phDeviceConfigData_t;

/**
 * @}
 */

/**
 * @brief  Structure lists out the UWB Device Info Parameters.
 */
/* @{ */
typedef struct phUwbDevCap
{
    /** Device Max Uci Payload Len */
    uint16_t length; // UTNI16 for future extensions
    uint8_t tlvBuffer[UCI_MAX_PAYLOAD_SIZE];
} phUwbDevCap_t;

/**
 * @brief  Enumeration lists out the Preferred Antenna used.
 *
 */
typedef enum
{
    kAntennaSecect_AntDefault = 0x00,
    kAntennaSecect_AntTop     = 0x01,
    kAntennaSecect_AntBottom  = 0x02,
} eAntennaSelect_t;
/* @}*/

/* @addtogroup uwb_apis_sr040 */

#endif // UWBAPI_TYPES_PROPRIETARY_SR040_H
